<?php
namespace app\index\model;
use think\exception\ErrorException;
use think\Model;
class Member extends Model
{

	function add($data){
		$result = $this->isUpdate(false)->allowField(true)->save($data);
		if($result){
			return true;
		}else{
			return false;
		}
	}
	
	function edit($data){
		$result = $this->isUpdate(true)->allowField(true)->save($data);
		if($result){
			return true;
		}else{
			return false;
		}
	}


    /**
     * 保存数据并返回主键id
     * @param $data
     * @return int|string
     */
	public static function add_user($data)
    {
        try{
            $id = self::insertGetId($data);
        }catch(ErrorException $errorException){
            return 0;
        }
        return $id;
    }

    /**
     * 修改用户信息
     * @param $user_id   用户id
     * @param $data   需要修改的数据
     * @return Member|int
     */
    public function edit_user($user_id,$data)
    {
        try{
            $id = self::where('userid',$user_id)->update($data);
        }catch(ErrorException $errorException){
            return 0;
        }
        return $id;
    }

}
